﻿using strange.extensions.command.impl;
using strange.extensions.dispatcher.eventdispatcher.api;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RequestCommand : EventCommand
{
    [Inject]
    public ISomeService ScoreService { get; set; }
    [Inject]
    public ISomeModel ScoreModel { get; set; }
    public override void Execute()
    {
        ScoreService.Request();
        ScoreService.dispatcher.AddListener(Events.REQUEST_COMPLETE, OnComplete);
    }
    /// <summary>
    /// 回调方法
    /// </summary>
    private void OnComplete(IEvent evt)
    {
        ScoreService.dispatcher.RemoveListener(Events.REQUEST_COMPLETE, OnComplete);
        int score = (int)evt.data;
        //更新UI
        dispatcher.Dispatch(Events.SCORE_CHANGE, score);
        //把数据保存到本地
        ScoreModel.Date = score;
    }

}
